// 小z的串串
#include <cstdio>
#include <string.h>
using namespace std;

char str[10010] = {0};
long long count;
long long sizze;
long long target;
long long temp;
long long i;

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        count = 0;
        i=0;
        memset(str, 0, sizeof(char)*10010);
        scanf("%s", str);
        scanf("%lld", &target);
        sizze = 10010;
        temp = 0;
        if(str[0] == 48 && str[1] > 57)
        {
            count++;
        }
        for(long long i=0; i<sizze; i++)
        {
            if(str[i] >= 48 && str[i] <= 57)
            {
                temp*= 10;
                temp += (str[i]-48);
                if(str[i] == 48)
                {
                    if(str[i-1] > 57 && str[i+1] >57)
                    {
                        count++;
                    }
                }
            }
            else
            {
                if(temp>0 && str[i] > 57)
                {
                    if(temp <= target)
                    {
                        count++;
                    }
                    temp = 0;
                }
            }
        }
        if (temp > 0)
        {
            if (temp <= target)
            {
                count++;
            }
            temp = 0;
        }
        if(str[sizze-1] == 48 && str[sizze-2] > 57)
        {
            count++;
        }
        printf("%lld\n", count);
    }
    return 0;
}